#pragma once
#include "message.grpc.pb.h"
#include "message.pb.h"
#include <cstdint>
#include <grpcpp/grpcpp.h>
#include <grpcpp/server_context.h>
#include <grpcpp/support/status.h>
#include <mutex>
#include <string>
#include <unordered_map>
struct ChatServer {
  std::string host;
  std::string port;
  std::string name;
  int con_count;
};

class StatusServiceImpl final : public message::StatusService::Service {
public:
  StatusServiceImpl();
  ~StatusServiceImpl();
  grpc::Status GetChatServer(grpc::ServerContext *context,
                             const message::GetChatServerReq *request,
                             message::GetChatServerRsp *reply);
  grpc::Status Login(grpc::ServerContext *context,
                     const message::LoginReq *request,
                     message::LoginRsp *reply);

private:
  void insertToken(int uid, const std::string &token);
  ChatServer getChatServer();
  std::unordered_map<std::string, ChatServer> _servers;
  std::mutex _server_mutex;
};